/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dbritos.labusers.app;

import java.util.List;

import com.dbritos.labusers.dao.HibernateUtil;
import com.dbritos.labusers.dao.RoleDaoImpl;
import com.dbritos.labusers.model.Role;

public class Main {
    
    public static void main(String[] args) {
        
        // Set up database table
        HibernateUtil.droptable("drop table ROLE");
        HibernateUtil.setup("create table ROLE (id int, name VARCHAR(20), description VARCHAR(100) )");
        
        // Create Dao object
        RoleDaoImpl roleDao = new RoleDaoImpl();
        
        // Perform create Dao operation
        System.out.println("Performing create Dao operation....");
        Role role1 = new Role();
        role1.setName("Administrators");
        role1.setDescription("Masters of the universe");
        roleDao.save(role1);
        
        Role role2 = new Role();
        role2.setName("Users");
        role2.setDescription("Standard users");
        Role roleToDelete = (Role)roleDao.save(role2);        
/*        
        Event event2 = new Event();
        event2.setName("Noname conference");
        eventDao.create(event2);
        
        // Perform find Dao operation
        System.out.println("Performing find Dao operation...");
        Event foundEvent = eventDao.find(event1.getId());
        System.out.println("Name of the event found = " + foundEvent.getName());
        
        // Perform update Dao operation
        System.out.println("Perrforming update Dao operation...");
        event1.setName("New Conference");
        eventDao.update(event1);
        
        // Perform findAll Dao operation
        System.out.println("Performing findAll Dao operation...");
        List eventList = eventDao.findAll();
        System.out.println("Number of entries in the database table = " + eventList.size());
        */
        // Display the contents of the database table
        HibernateUtil.checkData("select id, name, description from ROLE");
        roleDao.remove(roleToDelete.getId());
        HibernateUtil.checkData("select id, name, description from ROLE");
    }
    
}